package com.example.mobile2032021606168xmy0615classtest;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class UserRViewAdapter extends RecyclerView.Adapter<UserRViewAdapter.ViewHolder> {
    private List<Users>list;
    public UserRViewAdapter(List<Users>list){
        this.list=list;
    }


    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvItemId,tvItemName,tvItemAge,tvItemscore;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemId = itemView.findViewById(R.id.tv_item_id);
            tvItemName = itemView.findViewById(R.id.tv_item_name);
            tvItemAge =itemView.findViewById(R.id.tv_item_age);
            tvItemscore=itemView.findViewById(R.id.tv_item_score);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.activity_item_rv_main_users,parent,false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Users users = list.get(position);
        holder.tvItemId.setText(String.valueOf(users.get_id()));
        holder.tvItemName.setText(users.getName());
        holder.tvItemAge.setText(String.valueOf(users.getAge()));
        holder.tvItemscore.setText(String.valueOf(users.getScore()));

    }

    @Override
    public int getItemCount() {

        return list.size();
    }


}
